package practice_2025_10.practice_10_5;

class Solution {
    /**
     * 种花问题
     * 贪心
     * @param flowerbed
     * @param n
     * @return
     */
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        // 不打破规则情况下能种多少花
        // 花不能种植在相邻的地块上
        int len = flowerbed.length;
        int pre = -1, cur = 0, next = 1;
        int count = 0;
        for(; cur < len; cur++) {
            pre = cur - 1;
            next = cur + 1;
            if (count >= n) {
                return true;
            }
            if ((pre == -1 || flowerbed[pre] == 0) && (next >= len || flowerbed[next] == 0) && flowerbed[cur] == 0) {
                flowerbed[cur] = 1;
                count++;
            }
        }
        // System.out.println(count);
        return count >= n;
    }
}